package com.my.interview.jvm.study;

public class VolatileTest {

    public volatile static int race = 0;

    public
    synchronized
    static void increase(){
        race++;
    }

    public static final int THREAD_COUNT = 20;
    public static void main(String[] args) {

        Thread [] threads = new Thread[THREAD_COUNT];
        for(int i = 0;i < THREAD_COUNT;i++){
            threads[i] = new Thread(new Runnable() {
                @Override
                public void run() {
                    for(int j = 0; j< 10000;j++) {
                        increase();
                    }
                }
            });
            threads[i].start();
        }

        while (Thread.activeCount() > 1){
            Thread.yield();
            System.out.println("-----" + race);
        }
    }

}
